import { useState } from 'react'
import { getTemplateDetail } from '@/services/template'

type Props = {
    templateName: string
    pid: string | null
}

const useTemplate = (): [string, (template: string) => void, (templateName: string, patientNumber: string) => Promise<void>, boolean, string, (string) => void] => {
    const [template, setTemplate] = useState('')
    const [stepLoading, setStepLoading] = useState(false)
    const [blId, setBlId] = useState('')

    const getTemplate = async (templateId, patientNumber) => {
        setStepLoading(true)
        const res = await getTemplateDetail({ templateId, patientNumber })
        setStepLoading(false)
        setBlId(res.data?.blId)
        setTemplate(res.data?.content)
    }

    return [template, setTemplate, getTemplate, stepLoading, blId, setBlId]
}

export default useTemplate